home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / uemlsrc.arc / path.c < prev    next >
C/C++ Source or Header  |  1987-08-24  |  3KB  |  91 lines

  1. /* PATH.C  commands that deal with paths are in here */
  2.  
  3. #include "shell.h"
  4.  
  5. /* SETPATH set the current path and default drive.  This is needed on the
  6.  * ST for shell programs that expand wildcards incorrectly when given
  7.  * a command line which requests a drive other than the default.  The
  8.  * command also uses the aliases listed above.  Bound to CTLX-D.
  9.  */
  10. setpath(f, n)
  11. int f, n;
  12. {
  13.         register char *ptr;
  14.         extern char *index(),*alias();
  15.         char template[MAXINPUT+1];
  16.         char subdir[MAXINPUT+1];        /* handle multiple path */
  17.  
  18.         if (n == 0)
  19.                 {
  20.                 f = (int)Dgetdrv();
  21.                 Dgetpath(path,(f+1));
  22.                 mlwrite("Default drive: %c: Default path: %s",(f + 'A'),path);
  23.                 return(TRUE);
  24.                 }
  25.         mlreply("New drive and path: ",template,MAXINPUT-1);
  26.         if (template[0] == '~') /* use alias if possible */
  27.                 {
  28.                 if ((ptr=index(template,' '))!=(char *)NULL)
  29.                         *ptr = '\0';
  30.                 if ((ptr=index(template,'\t'))!=(char *)NULL)
  31.                         *ptr = '\0';
  32.                 if ((ptr=index(template,'\\'))!=(char *)NULL)
  33.                         {
  34.                         *ptr = '\0';
  35.                         ++ptr;
  36.                         strcpy(subdir,ptr);
  37.                         n = 0;
  38.                         }
  39.                 if (alias(&path[0],&template[1]) == (char *)NULL)
  40.                         return(FALSE);
  41.                 if (n==0)
  42.                         strcat(path,subdir);
  43.                 }
  44.         else
  45.                 strcpy(path,template);
  46.         if ((ptr=index(path,':'))!=(char *)NULL)
  47.                 {
  48.                 --ptr;
  49.                 f = (int)toupper(*ptr);
  50.                 if (f < 'A' || f > 'P')
  51.                         {
  52.                         mlwrite("Illegal drive specification %c:",f);
  53.                         return(FALSE);
  54.                         }
  55.                 f -= 'A';
  56.                 Dsetdrv(f);
  57.                 }
  58.         Dsetpath(path);
  59.         return(TRUE);
  60. }
  61.  
  62. /* look up the string template in the known aliased names.  If it's a
  63.  * known alias, copy the actual path into dirpath and return a pointer
  64.  * to dirpath.  If it is not legit, complain and return NULL.  Called
  65.  * by any command that looks at a file on disk.
  66.  */
  67. char *
  68. alias(dirpath, template)
  69. register char *dirpath;
  70. register char *template;
  71. {
  72.         register ALITAB *apt;
  73.  
  74.         apt = aheadp;
  75.         if (apt == NULL)
  76.                 {
  77.                 mlwrite("No aliases defined");
  78.                 return((char *)NULL);
  79.                 }
  80.         while (apt)
  81.                 {
  82.                 if (strcmp(template,apt->alias)==NULL)
  83.                         {
  84.                         strncpy(dirpath,apt->value,MAXINPUT);
  85.                         return(dirpath);
  86.                         }
  87.                 apt=apt->a_forw;
  88.                 }
  89.         return((char *)NULL);
  90. }
  91.